package com.zq.it.action.admin;

import java.util.List;

import javax.annotation.Resource;

import com.zq.it.action.BaseAction;
import com.zq.it.pojo.Major;
import com.zq.it.service.admin.MajorService;
import com.zq.it.tool.Constant;
import com.zq.it.tool.FileName;
import com.zq.it.tool.FileType;
import com.zq.it.tool.HeadTitle;

import net.sf.json.JSONArray;
public class MajorAction extends BaseAction {
	
	private static final long serialVersionUID = 1L;
	@Resource
	private MajorService majorService;	
	private Major major;
	private String type;
	private int [] majorGroupId;	
	private String param;

	
	public void searchMajorList(){
		List list=majorService.getAllMajor();
		uploadList(com.zq.it.tool.EtyLsName.MAJOR_LS.name(),list);
		print(JSONArray.fromObject(list,Constant.getJcf("YYYY-MM-dd")).toString(),"UTF-8","APPLICATION/JSON");
	}
	public void searchMajorListFromType(){
		List list=majorService.getMajorListByType(type, param);
		uploadList(com.zq.it.tool.EtyLsName.MAJOR_LS.name(),list);
		print(JSONArray.fromObject(list,Constant.getJcf("YYYY-MM-dd")).toString(),"UTF-8","APPLICATION/JSON");
	}
	
	public void deleteMajorGroups(){
		majorService.removeAllMajor(majorGroupId);
		 print("已删除"+majorGroupId.length+"条记录！","UTF-8","text/html");
	}
	
	public void searchAcmyNameAndId(){
		//String str=JSONArray.fromObject(majorService.getAcmyNameAndId()).toString();
		//System.out.println(str);
		print(toJSON(majorService.getAcmyNameAndId()).toString(),"UTF-8","APPLICATION/JSON");
	}
	public void addMajorPo(){
		if(major.getAcademy().getAcademyId()==0)
			major.setAcademy(null);
		majorService.addMajor(major);
		print("<script>parent.closeWindow('已添加');</script>","UTF-8","text/html");	
	}
	public void modifyMajorPo(){
		majorService.renewalMajor(major);
		print("<script>parent.closeWindow('已修改！');</script>","UTF-8","text/html");	
	}

	public void importMajorList(){	
		String msgStr="";
		List<Major> list=majorService.importMajorList(getUpload());
		if(list.size()>0){
		 getRequest().getSession().setAttribute("existMajorList",list);	
		 msgStr="existList";
		}else{
			msgStr="已导入成功!";
		}
		print("<script>parent.importBackResult('"+msgStr+"','webpage/adminpage/major/mexisMajor.jsp');</script>","UTF-8","TEXT/HTML");
	}
	public void exportMajorList(){				
		download(majorService.exportMajorList(HeadTitle.CN_MAJORHEAD.getArray(),(List)getHttpSession().getAttribute(com.zq.it.tool.EtyLsName.MAJOR_LS.name())),FileName.MAJOR_LIST_NAME.toString()+FileType.XLSX);
	}
	
	public Major getMajor() {
		return major;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getParam() {
		return param;
	}
	public void setParam(String param) {
		this.param = param;
	}
	public void setMajor(Major major){
		this.major = major;
	}
	public void addMajor() {
		majorService.addMajor(major);
		
	}
	public int[] getMajorGroupId(){
		return majorGroupId;
	}
	public void setMajorGroupId(int[] majorGroupId){
		this.majorGroupId = majorGroupId;
	}
	public void deleteMajor(){
		majorService.removeMajor(major);
	}
}
